#!/usr/bin/python
# -*- coding: utf-8 -*-

'''登录世纪佳缘----测试'''


import sys
import requests
from lxml import html
import utils


url = 'http://login.jiayuan.com'
session = requests.Session()
request_headers = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                   'Accept-Encoding':'gzip,deflate',
                   'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
                   'Connection':'keep-alive',
                   'Host':'login.jiayuan.com',
                   'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
                   }
response = session.get(url, headers=request_headers)

print response.status_code
if response.status_code in (404, 505):
    response.raise_for_status()
    sys.exit(1)
print
for h in response.headers:
    print h, ':', response.headers.get(h)
print
for c in dict(response.cookies):
    print c, ':', response.cookies.get(c)
print

xpath = r'//*[@id="login"]/input[1]'
doc = html.document_fromstring(response.text)
doms = doc.xpath('//*[@id="login"]/input[1]')
print
print doms[0].value


passport_url = r'https://passport.jiayuan.com/dologin.php?pre_url=http://www.jiayuan.com/usercp'
headers = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                   'Accept-Encoding':'gzip,deflate',
                   'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
                   'Connection':'keep-alive',
                   'Host':'login.jiayuan.com',
                   'Referer':'http://login.jiayuan.com/',
                   'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
                   }
payload = {'name':'baixuexue123@sina.com',
            'password':'xuebailove321',
            '_s_x_id':doms[0].value,
            'ljg_login':'1',
            'm_p_l':'1',
            'channel':'0',
            'position':'0',
            'remem_pass':'on',
        }
##header, message = utils.https_post(passport_url, form)
##print header
##print
##print message


response = session.post(passport_url, data=payload, headers=headers, verify=True)
print response.status_code



# if __name__ == '__main__':
#     login()










